package touchtrack.model.track;

/**
 * TrackMatch
 * 
 * Abstract class representing a match between two Tracks.
 * 
 * @author	MuMe09 team 6
 * 			http://mumetech.wordpress.com/
 */
public class TrackMatch
{
	/**
	 * Constructor.
	 * 
	 * @param 	Track track1
	 * @param 	Track track2
	 * @param 	float similarity
	 */
	public TrackMatch(Track track1, Track track2, float similarity)
	{
		this.track1 = track1;
		this.track2 = track2;
		this.similarity = similarity;
	}
	
	/***************************************************************************
	 * 							Tracks
	 ***************************************************************************/
	
	/**
	 * @param	TrackInterface
	 * @return	boolean
	 */
	public boolean contains(TrackInterface track)
	{
		return track1.equals(track) || track2.equals(track);
	}
	
	/**
	 * @param	TrackInterface
	 * @param	TrackInterface
	 * @return	boolean
	 */
	public boolean contains(TrackInterface track1, TrackInterface track2)
	{
		return this.contains(track1) && this.contains(track2);
	}
	
	/**
	 * @param 	TrackInterface
	 * @return	Track
	 */
	public Track getOther(TrackInterface track)
	{
		return track.equals(track1) ? track2 : track1;
	}
	
	private Track track1;
	private Track track2;
	
	/***************************************************************************
	 * 							Similarity
	 ***************************************************************************/
	
	/**
	 * @return	float similarity
	 */
	public float getSimilarity()
	{
		return this.similarity;
	}

	private float similarity;
	
	/***************************************************************************
	 * 							Java stuff
	 ***************************************************************************/
	
	/**
	 * Compares TrackMatches.
	 * 
	 * @param	Object obj
	 * @return	boolean
	 */
	public boolean equals(Object obj)
	{
		if (obj instanceof TrackMatch) {
			TrackMatch match = (TrackMatch) obj;
			return match.contains(track1, track2);
		}
		
		return false;
	}
	
	/**
	 * @return	String
	 */
	public String toString()
	{
		return "Match between " + track1 + " and " + track2;
	}
}